<?php

/**
 * This is the model class for table "bidder".
 *
 * The followings are the available columns in table 'bidder':
 * @property integer $bid
 * @property char $tid
 * @property integer $sid
 * @property integer $cid
 * @property integer $purchase
 * @property double $bail
 * @property integer $bidstate
 * @property integer $bailstate
 * @property double $price
 * @property double $fee
 * @property integer $feestate
 * @property integer $mapstate
 * @property string $remarks
 */
class Bidder extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @param string $className active record class name.
	 * @return Bidder the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'bidder';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('tid, sid, cid', 'required'),
			array('sid, cid, purchase, bidstate, bailstate, feestate, mapstate', 'numerical', 'integerOnly'=>true),
			array('bail, price, fee', 'numerical'),
			array('remarks', 'length', 'max'=>256),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('bid, tid, sid, cid, purchase, bail, bidstate, bailstate, price, fee, feestate, mapstate, remarks', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'supplies'=>array(self::BELONGS_TO,'Supplies','sid'),
			'contact'=>array(self::BELONGS_TO,'Contact','cid'),
			'tender'=>array(self::BELONGS_TO,'Tender','tid'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'bid' => Yii::t('tender','Bid'),
			'tid' => Yii::t('tender','Tid'),
			'sid' => Yii::t('tender','Sid'),
			'cid' => Yii::t('tender','Cid'),
			'purchase' => Yii::t('tender','Purchase'),
			'bail' => Yii::t('tender','Bail'),
			'bidstate' => Yii::t('tender','Bidstate'),
			'bailstate' => Yii::t('tender','Bailstate'),
			'price' => Yii::t('tender','Price'),
			'fee' => Yii::t('tender','Fee'),
			'feestate' => Yii::t('tender','Feestate'),
			'mapstate' => Yii::t('tender','Mapstate'),
			'remarks' => Yii::t('tender','Remarks'),
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('bid',$this->bid);
		$criteria->compare('tid',$this->tid);
		$criteria->compare('sid',$this->sid);
		$criteria->compare('cid',$this->cid);
		$criteria->compare('purchase',$this->purchase);
		$criteria->compare('bail',$this->bail);
		$criteria->compare('bidstate',$this->bidstate);
		$criteria->compare('bailstate',$this->bailstate);
		$criteria->compare('price',$this->price);
		$criteria->compare('fee',$this->fee);
		$criteria->compare('feestate',$this->feestate);
		$criteria->compare('mapstate',$this->mapstate);
		$criteria->compare('remarks',$this->remarks,true);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}
}